/**
 * @file field
 * @author fanxueliang@qq.com
 */
import type {ObjectSpecItem, LikeFieldType, ObjectField} from '../interface';
import {getBasicField} from '../util';

export function createObjectField(spec: ObjectSpecItem, showIndex: number, path: string) {
    let component = 'Block';
    if (spec.ui) {
        component = spec.ui;
    }
    const children: LikeFieldType[] = [];
    const basicField = getBasicField(spec, path, showIndex);
    return {
        ...basicField,
        type: 'OBJECT',
        isLeaf: !children.length,
        spec,
        component,
        children
    } as ObjectField;
}
